package com.jzo2o.foundations.controller.operation;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jzo2o.api.foundations.dto.response.ServeItemResDTO;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.common.model.Result;
import com.jzo2o.foundations.model.domain.Serve;
import com.jzo2o.foundations.model.dto.request.*;
import com.jzo2o.foundations.model.dto.response.RegionResDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeItemService;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 服务表 前端控制器
 * </p>
 *
 * @author itcast
 * @since 2023-07-03
 */
@Validated
@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务相关接口")
public class ServeController {
    @Autowired
    private IServeService serveService;

    @GetMapping("/page")
    @ApiOperation("区域服务分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO) {
        return serveService.findByPage(servePageQueryReqDTO);
    }

    @PostMapping("/batch")
    @ApiOperation("区域服务新增")
    public Result add(@RequestBody List<ServeUpsertReqDTO> dtoList){
        serveService.add(dtoList);
        return Result.ok();
    }

    @PutMapping("/{id}")
    @ApiOperation("区域服务修改")
    public Result update(@PathVariable("id") Long id, BigDecimal  price){
        Serve serve = new Serve();
        serve.setId(id);
        serve.setPrice(price);
        serveService.updateById(serve);
        return Result.ok();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("区域服务删除")
    public Result delete(@PathVariable("id") Long id){
        serveService.deleteById(id);
        return Result.ok();
    }

    @PutMapping("/onSale/{id}")
    @ApiOperation("区域服务上架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "区域服务id", required = true, dataTypeClass = Long.class)
    })
    public void onSale(@PathVariable("id") Long id) {
        serveService.onSale(id);
    }

    @PutMapping("/offSale/{id}")
    @ApiOperation("区域服务下架")
    public void offSale(@PathVariable("id") Long id) {
        serveService.offSale(id);
    }

    @PutMapping("/onHot/{id}")
    @ApiOperation("区域服务设为热门")
    public void onHot(@PathVariable("id") Long id) {
        Serve serve = new Serve();
        serve.setId(id);
        serve.setIsHot(1);
        serve.setHotTimeStamp(new Date().getTime());
        serveService.updateById(serve);
    }

    @PutMapping("/offHot/{id}")
    @ApiOperation("区域服务取消热门")
    public void offHot(@PathVariable("id") Long id) {
        Serve serve = new Serve();
        serve.setId(id);
        serve.setIsHot(0);
        serveService.updateById(serve);
    }
}
